package com.example.springboot.ytest.ytest;

import java.lang.reflect.InvocationTargetException;

import org.apache.commons.beanutils.BeanUtils;
import com.alibaba.fastjson.JSON;

class BeanTest{
    private String name;
    private int age;
    
    public BeanTest() {
        super();
        this.name = "";
        this.age = 0;
    }
    public BeanTest(String name, int age) {
        super();
        this.name = name;
        this.age = age;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
}

/**
 * 测试 org.springframework.beans.BeanUtils
 * 
 * @author: yeyi
 * @date: 2019年7月2日
 */
public class BeanUtilsTest {
	public static void copyProperties() {
	    BeanTest bt = new BeanTest("路飞", 17);
	    BeanTest bt2 = new BeanTest();
	    try {
	        // 同类反而不行
            BeanUtils.copyProperties(bt2, bt);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
	    System.out.println(JSON.toJSON(bt));
	    System.out.println(JSON.toJSON(bt2));
	}
	
	public static void main(String[] args) {
	    copyProperties();
	}
}
